package com.ym.b2b.charge.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ym.b2b.charge.service.EmBLogService;
import com.ym.b2b.charge.vo.EmBLogVO;
import com.ym.b2b.commons.controller.BaseController;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;
import com.zc.export.ExcelUtil;

/**
 * @ClassName: ManageEmBLogController
 * @Author tangxj
 * @Date 2015-5-8 下午2:54:12
 * @Modify
 * @CopyRight B2B小组
 */

@Controller
@RequestMapping("/log")
public class ManageEmBLogController extends BaseController {


    @Autowired
    private EmBLogService  emBLogService;

    @RequestMapping("searchPageEmBLog.do")
    @ResponseBody
    public Result searchPageEmBLog(EmBLogVO emBLogVO, Page<EmBLogVO> page, HttpServletRequest req) {

        Result result = new Result();
        try {
            result = emBLogService.searchPageEmBLog(emBLogVO, page);
        } catch (Exception e) {
            result.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return result;

    }

    @RequestMapping(value = "searchPageEmBLogExcel.do")
    @ResponseBody
    public Result searchPageEmBLogExcel(EmBLogVO emBLogVO, Page<EmBLogVO> page, String loadType) {
        Result ret = new Result();
        try {
            if (loadType == null || loadType.equals("")) {
                ret.setCode(Result.CODE_100);
                ret.setResult("loadType 参数 '数量'  不能为空!");
                return ret;
            }
            page.setPageable("true");
            page.setPageSize(Integer.parseInt(loadType));
            page.setStartRow(1);
            ret = emBLogService.searchPageEmBLog(emBLogVO, page);
            ExcelUtil<EmBLogVO> excelUtil = new ExcelUtil<EmBLogVO>();
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("model", ret.getRows());
            ret = excelUtil.createExcel("logListExcel", map);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            ret.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return ret;
    }

  
}
